package com.boot.unity.api.wx.controller;

import com.boot.unity.api.wx.service.WxCoachservice;
import com.github.pagehelper.PageInfo;
import com.sun.istack.internal.NotNull;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 教练服务
 */
@RestController
@RequestMapping("/wx/coachs")
@Validated
public class WxCoachsController {
	private final Log logger = LogFactory.getLog(WxCoachsController.class);

	@Autowired
	private WxCoachservice wxCoachservice;


	/**
	 * 获取教练列表
	 * <p>
	 * @Param regionId	区域id
	 * @Param starRating	星级
	 * @param page       分页页数
	 * @param limit       分页大小
	 * @param sort       排序方式，支持"add_time", "retail_price"或"name"
	 * @param order      排序类型，顺序或者降序
	 * @return  教练信息
	 */
	@GetMapping("list")
	public Object list(Integer starRating, String keyword, Integer schoolId, Integer type, Integer page, Integer limit, String sort, String order) {
		if (sort == null){
			sort = "add_time";
		}
		if (type == null){
			type = 0;
		}
		if (order == null){
			order = "desc";
		}
		return wxCoachservice.list(starRating, keyword, schoolId, type, page, limit, sort,order);
	}

	/**
	 * 教练详情
	 * @param id     教练ID
	 * @return 教练详情
	 */
	@GetMapping("detail")
	public Object detail( @NotNull Integer id) {
		return wxCoachservice.detail(id);

	}


	/**
	 * 获取教练列表
	 * <p>
	 * @Param regionId	区域id
	 * @Param starRating	星级
	 * @param page       分页页数
	 * @param limit       分页大小
	 * @param sort       排序方式，支持"add_time", "retail_price"或"name"
	 * @param order      排序类型，顺序或者降序
	 * @return  教练信息
	 */
	@GetMapping("listStar")
	public Object listStar(Integer regionId, Integer starRating, String keyword, Integer schoolId, Integer type, Integer page, Integer limit, String sort, String order) {
		if (sort == null){
			sort = "add_time";
		}
		if (page == null){
			page = 1;
		}
		if (limit == null){
			limit = 10;
		}
		if (type == null){
			type = 0;
		}
		if (order == null){
			order = "desc";
		}
		return wxCoachservice.listStar(regionId, starRating, keyword, schoolId, type, page, limit,sort,order);
	}
}
